<?php


namespace app\common\model\village;

use app\common\model\BaseModel;
use Lvht\GeoHash;


/**
 * 模型
 */
class Village extends BaseModel
{
    protected $pk = 'id';

    protected $name = 'shop_village';
    /**
     * 隐藏字段
     * @var array
     */
    protected $hidden = [
        'app_id',
        'update_time',
    ];

    /**
     * 获取列表数据
     */
    public function getList($data = null, $status = '',$type=1)
    {
        $model = $this;
        !empty($status) && $model = $model->where('status', '=', (int)$status);
        if($type==1){
            $list = $model->order(['id' => 'desc'])->paginate($data);
        }else{
            $list = $model->order(['id' => 'desc'])->select();
        }

        return $list;
    }


    /**
     * 详情
     */
    public static function detail($id)
    {
        return (new static())->where('id',$id)->find();
    }


    /**
     * 新增记录
     */
    public function add($data)
    {
        $data = $this->createData($data);
        return self::create($data);
    }

    /**
     * 编辑记录
     */
    public function edit($data)
    {
        return $this->save($this->createData($data));
    }

    /**
     * 创建数据
     */
    private function createData($data)
    {
        $data['app_id'] = self::$app_id;
        return $data;
    }

    /**
     * 门店状态
     */
    public function getStatusAttr($value)
    {
        $status = [0 => '禁用', 1 => '启用'];
        return ['text' => $status[$value], 'value' => $value];
    }


}